#include <stdio.h>
#include "fcntl.h"
#include <unistd.h>

int main(int argc, char *argv[])
{
    int fd1 = open("love.txt", O_RDONLY);
    if( fd1 == -1)
    {
        printf("open error\n");
    }
    
    int fd2 = open("love2.txt", O_CREAT | O_WRONLY | O_APPEND, 0644);
    if( fd2 == -1)
    {
        printf("open error\n");
    }

    char data_buf[100];

    int len;
    if( (len = read(fd1 , data_buf , sizeof(data_buf))) > 0 )
    {
        
        write(fd2, data_buf, len);

        write(STDOUT_FILENO, data_buf, len);

        
    }

    close(fd1);
    close(fd2);

    return 0;
}